AGI Disk Free! Decryptor 1.1 (Cold Turkey - Dec 2014)
-----------------------------------------------------
This is a modified version of Brian Provinciano's AGI Decryptor. It allows
you to decrypt your old Sierra AGI games WITHOUT having to have access
to a DOS machine or a having the decryption key in the sierra.com loader.

There are three .exe's provided
--------------------------------
* win_decrypt.exe - Runs on modern Windows!!
* DOS16_DE.EXE - Can be used from Dos and Dosbox. Most Dos users should be
happy with this version. Uses realmode Dos.
* DOS32_DE.EXE - Protected mode version. Requires a DPMI host like CWSDPMI,
or Windows 9x. Really only included for fun.

Usage
-----
1) Copy the sierra.com (or whatever your .com loader is) and the AGI file
from your game to the same directory as this program.
2) If your loader is named sierra.com, just run the correct .exe and it will
create an AGI.exe you can use to run your game!
3) If your loader is not named sierra.com (must be a .com file though), run
the appropriate .exe with the loader name as the first argument.

source - Directory containing the source code of this program. It is written
in old school C, and should compile on just about anything!

getkey - Directory containing my modified version of SUP (by Anders M. Olsson)
which allows you to get the key off of your keydisk. It requires that you run 
it in pure Dos mode on an old dos machine. It will write the key to c:\sierra.key
The Pascal source is also included. You can compile it with the free Borland
Turbo Pascal environment: http://edn.embarcadero.com/article/20803

Nerd Notes
----------
This program was written because I was tired of having to use an old Dos
PC to decrypt my AGI games so I could play them in Dosbox. Because
Sierra used the same decryption key (just with different offsets),
I figured I could dump the key once and use it to decrypt any game.

According to: http://www.agidev.com/articles/agispec/agispecs-3.html#crypt
The key is on Track 6 of the keydisk. This was confirmed by inspecting
the SUP source code and its AMAZING CheckTrack6 function. This function
adjusts the Disk Base Table (aka. The Disk Parameter Table) so that it
reads 8192 byte sectors! I really just added a few lines to write this
sector out to a file.

The sierra.com program is responsible for starting the decryption process of
AGI games. Inside of this file, directly proceeding "keyOfs" are two bytes
which indicate the offset of the key from the start of Track6. Two interesting
things to note here are:
1) The offset is stored in little endian byte ordering, so the bytes need to
be reversed to create the integer.
2) I have yet to see a game where the most significant byte is anything other
than zero. If this holds true, the largest the offset can be is 255 bytes.
Since the key is 128 bytes, it would imply of the 8192 bytes of Track6,
only 384 are useful as the key. That being said, I have yet to see an
offset larger than 128, which may imply that only the first 255 bytes of
Track6 are even useful. Regardless, I have included the whole 8192 just in case,
and for completeness. I'm sure your multi terrabyte hard drive and 16 gigs of ram
won't mind :)

I simply read the whole 8192 bytes from the dumped key, load the offset of the key
from the loader, put the 128 bytes from the key (starting at the offset)
into the decryption string variable, and let Brian's awesome decryption
algorith take care of the rest!!

Interesting reading:
http://webpages.charter.net/danrollins/techhelp/0052.HTM
http://en.wikipedia.org/wiki/BIOS_interrupt_call
http://support.microsoft.com/kb/71486
http://webpages.charter.net/danrollins/techhelp/0188.HTM
http://stackoverflow.com/questions/1989589/assembly-int-13h-read-disk-problem


Tools:
Dos protected mode compiler: http://www.delorie.com/djgpp/
Dos realmode compiler: http://www.openwatcom.org/index.php/Downloads
Turbo Pascal 5.5: http://edn.embarcadero.com/article/20803
Hex Editor: http://mh-nexus.de/en/hxd/

Thnx

Cold Turkey


